/**************
 *  Array Remove - By John Resig (MIT Licensed)
 *  http://stackoverflow.com/questions/500606/javascript-array-delete-elements
 *  and here's some examples of how it could be used:
 *
 *  Remove the second item from the array
 *  array.remove(1);
 *
 *  Remove the second-to-last item from the array
 *  array.remove(-2);
 *
 *  Remove the second and third items from the array
 *  array.remove(1,2);
 *
 *	Remove the last and second-to-last items from the array
 *	array.remove(-2,-1);
 **************/
Array.prototype.remove = function(from, to) {
  var rest = this.slice((to || from) + 1 || this.length);
  this.length = from < 0 ? this.length + from : from;
  return this.push.apply(this, rest);
};

if (!Array.prototype.indexOf) {
  Array.prototype.indexOf = function (obj, fromIndex) {
    if (fromIndex == null) {
        fromIndex = 0;
    } else if (fromIndex < 0) {
        fromIndex = Math.max(0, this.length + fromIndex);
    }
    for (var i = fromIndex, j = this.length; i < j; i++) {
        if (this[i] === obj)
            return i;
    }
    return -1;
  };
}

Array.prototype.include = function(target) {
  return (this.indexOf(target) != -1);
};

Array.prototype.max = function () {
	return Math.max.apply(Math, this);
}

Element.prototype.remove = function() {
  this.parentElement.removeChild(this);
}
NodeList.prototype.remove = HTMLCollection.prototype.remove = function() {
    for(var i = 0, len = this.length; i < len; i++) {
        if(this[i] && this[i].parentElement) {
            this[i].parentElement.removeChild(this[i]);
        }
    }
}
if(!document.getElementsByClassName){
	Node.prototype.getElementsByClassName = function(cn) {
	  for (var r=[], e=this.getElementsByTagName('*'), i=e.length; i--;) {
	    if ((' '+e[i].className+' ').indexOf(' '+cn+' ')>-1) {
	      r.push(e[i]);
	    }
	  }
	  return r;
	}
}

Element.prototype.hasClassName = function(name) {
	return	new RegExp("(?:^|\\s+)" + name + "(?:\\s+|$)").test(this.className);
};

Element.prototype.addClassName = function(name) {
	t=name.split(' ');
	for(var i=0; i<t.length; i++){
		if ( !this.hasClassName( t[i] ) ) {
			this.className = this.className ? [this.className, t[i] ].join(' ') : t[i];
		}
	}
};

Element.prototype.removeClassName = function(name) {
	t=name.split(' ');
	for(var i=0; i<t.length; i++){
		if (this.hasClassName(t[i])) {
			var c = this.className;
			this.className = c.replace(new RegExp("(?:^|\\s+)" + t[i] + "(?:\\s+|$)", "g"), "");
		}
	}
};

//Help functions
function msg( text, marker ){
	if( typeof(marker)=='undefined' ) marker='msg';
	alert(marker+': '+text);
}
function err(text){
  msg( text, 'err' );
}